package io.chenglicun.common.trans.service.impl.db.driver;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import io.chenglicun.common.entity.BaseEntity;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

@Component
public class MybatisTransDriver implements TransDriver {

    @Override
    public List<? extends BaseEntity> findByIds(List<? extends Serializable> ids, Class<? extends BaseEntity> targetClass) {
        try (SqlSession sqlSession = SqlHelper.sqlSession(targetClass)) {
            BaseMapper<? extends BaseEntity> mapper = SqlHelper.getMapper(targetClass, sqlSession);
            return mapper.selectBatchIds(ids);
        }
    }
    
}
